package com.zhumr.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhumr.model.ScriptInfo;
import com.zhumr.service.IScriptInfoService;

/**
 * 故事
 * 
 * @author HP
 *
 */
@Controller
@RequestMapping("/webScript")
public class ScriptInfoController {
	@Autowired
	private IScriptInfoService scriptService;

	@RequestMapping("/getAllScript")
	@ResponseBody
	public Map<String, Object> getAllScript(HttpServletRequest request, String likeString, String StoryType) {

		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("StoryType", StoryType);
		paramMap.put("likeString", likeString);

		List<ScriptInfo> scriptList = scriptService.getAllScript(paramMap);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (scriptList != null) {
			resultMap.put("code", "0");
			resultMap.put("script", scriptList);
		} else {
			resultMap.put("code", "1");
			resultMap.put("script", null);
		}
		return resultMap;
	}

	@RequestMapping("/getScriptById")
	@ResponseBody
	public Map<String, Object> getScriptById(HttpServletRequest request, int id) {

		ScriptInfo script = scriptService.getScriptById(id);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		if (script != null) {
			resultMap.put("code", "0");
			resultMap.put("script", script);
		} else {
			resultMap.put("code", "1");
			resultMap.put("script", null);
		}
		return resultMap;
	}
}
